home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / MEMTRANS.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  1KB  |  46 lines

  1. /*  File   : memtrans.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 2 June 1984
  4.     Defines: memtrans()
  5.  
  6.     memtrans(dst, src, from, to, len)
  7.     copies exactly len characters from src[] to dst[], translating chars
  8.     in from[] to corresponding characters in to[].   From[] and to[] are
  9.     handled by _str2map. BEWARE: _str2map normally expects characters in
  10.     the range 0..127.  The Vax MOVTC instruction thinks its table is 256
  11.     bytes long; if you want to translate arbitrary bytes you'd better be
  12.     sure that the _map_vec array is 256 bytes long.  As distributed, the
  13.     memtrans function is only for translating ASCII (to 8-bit codes).
  14.  
  15.     The VaxAsm code can only handle 0 <= len < 2^16, and is presented as
  16.     usual for your interest and amusement.  Why *do* designers of 32-bit
  17.     machines put 16-bit limits on strings?  (Dec aren't the only ones.)
  18. */
  19.  
  20. #include "strings.h"
  21. #include "_str2map.h"
  22.  
  23. #if    VaxAsm
  24.  
  25. void memtrans(dst, src, from, to, len)
  26.     _char_ *dst, *src, *from, *to;
  27.     int len;
  28.     {
  29.        _str2map(0, from, to);
  30.        asm("movtc 20(ap),*8(ap),$0,__map_vec,20(ap),*4(ap)");
  31.     }
  32.  
  33. #else  ~VaxAsm
  34.  
  35. void memtrans(dst, src, from, to, len)
  36.     register _char_ *dst, *src;
  37.     _char_ *from, *to;
  38.     register int len;
  39.     {
  40.        _str2map(0, from, to);
  41.        while (--len >= 0) *dst++ = _map_vec[*src++];
  42.     }
  43.  
  44. #endif VaxAsm
  45.  
  46.